package cn.itcast.java.charstream;

import java.io.*;

/**
 * Author itcast
 * Date 2021/10/13 17:44
 * Desc TODO
 */
public class BufferedCopyFile {
    public static void main(String[] args) {
        try {
            FileReader fileReader = new FileReader("data/input.dat");
            //定义读取缓存
            BufferedReader reader = new BufferedReader(fileReader);
            FileWriter fileWriter = new FileWriter("data/output.dat");
            //定义写出缓存对象
            BufferedWriter writer = new BufferedWriter(fileWriter);
            char[] bts = new char[1024];
            int len = 0;
            while((len = reader.read(bts))!=-1){
                System.out.println(new String(bts,0,len));
                writer.write(bts,0,len);
            }
            writer.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {

        }
    }
}
